package com.ruoyi.boc.utils;

import com.ruoyi.boc.domain.BocLakeTable;
import com.ruoyi.common.constant.GenConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.apache.velocity.VelocityContext;

import java.util.List;
import java.util.StringJoiner;

public class LakeVelocityUtils {

    /**
     * 设置模板变量信息
     *
     * @return 模板列表
     */
    public static VelocityContext prepareLakeContext(List<String> column, BocLakeTable bocLakeTable)
    {
        VelocityContext velocityContext = new VelocityContext();
        velocityContext.put("column", converCol(column));
        velocityContext.put("tableName", bocLakeTable.getTableName());
        velocityContext.put("fileName", bocLakeTable.getLakeName());
        velocityContext.put("increaseAll", bocLakeTable.getIncreaseAll());
        return velocityContext;
    }

    //不同的数据库拼接方式不同
    private static String converCol(List<String> columnNames){
        StringJoiner joiner = new StringJoiner(", ", "", "");
        for (String columnName : columnNames) {
            joiner.add("IFNULL(`" + columnName + "`, '')");
        }
        // 输出结果
        String result = joiner.toString();
        return result;
    }
}
